package com.su27.document;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.su27.document.config.ConfigReader;
import com.su27.document.util.FileUtil;
import com.su27.web.Doc;

public class DocumentData {
	private static final Map<String,String> doc_map = new HashMap<String,String>();
	private static final List<Doc> doc_list = new ArrayList<Doc>();
	
	public static String doc_path = null;
	static {
	try {
		doc_path = ConfigReader.getString("doc.path");
	} catch (IOException e) {
		e.printStackTrace();
	}
	}
	private static void init() {
		List<String> files = FileUtil.getFilesFromPath(doc_path);
		doc_map.clear();
		doc_list.clear();
		for (int i = 0 ; i < files.size() ; i++) {
			String key = String.valueOf(i);
			doc_map.put(key, files.get(i));
			doc_list.add(new Doc(key,files.get(i)));
		}
	}
	
	public static Map<String,String> getDocMap() {
		init();
		return doc_map;
	}
	
	public static List<Doc> getDocList() {
		init();
		return doc_list;
	}
	public static void main(String[] args) {
		DocumentData.init();
		System.out.println(doc_map);
	}
}
